package com.hkts.naturalgasauthentication.base.dao;

import com.hkts.naturalgasauthentication.base.entity.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.persistence.Transient;
import java.util.List;
import java.util.Optional;

public interface HontUserDao extends ManagementBaseDao<User,String> {
   /**
    * 通过用户名获取用户
    * @param username
    * @return
    */
   User findByUserName(String username);

   /**
    * 查找昵称
    * @param nickName
    * @return
    */
   User findByNickName(String nickName);

   List<User> findByNickNameLike(String nickName);

   /**
    * 通过手机获取用户
    * @param mobile
    * @return
    */
   User findByMobile(String mobile);

   /**
    * 通过邮件获取用户
    * @param email
    * @return
    */
   User findByEmail(String email);

   /**
    * 通过部门id获取
    * @param departmentId
    * @return
    */
   List<User> findByDepartmentId(String departmentId);
   @Transient
   @Modifying//增删改必须有这个注解
   @Query(value = "update user set open_id=:openid where id=:id",nativeQuery = true)
   void updateopenId(String openid,String id);

   Optional<User> findById(String id);

    @Query("from User  where id<>:id and mobile=:mobile")
    List<User> findByMobileAndId(String id, String mobile);
    @Query("from User where id in (:ids)")
   List<User> getUsersByuserIds(@Param("ids") List<String> ids);

    User findByOpenId(String openId);

   /*@Query("from User  where mobile=:mobile and userFlag=:flag")
   List<User> findByMobileAndFlag(String mobile,Integer flag);

   @Query("from User  where mobile=:mobile and userFlag=:flag")
   List<User> customFind(String mobile,Integer flag);

   @Query("from User  where departmentId=:departmentId and userFlag=:flag")
   List<User>  findByDepartmentIdAndFlag(String departmentId,Integer flag);*/
}
